package com.arch.dev.client.view.ui;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;

public class LinkCell extends AbstractCell<String>{

    /**

     * The HTML templates used to render the cell.

     */

    interface Templates extends SafeHtmlTemplates {

      /**

       * The template for this Cell, which includes styles and a value.

       *

       * @param styles the styles to include in the style attribute of the div

       * @param value the safe value. Since the value type is {@link SafeHtml},

       *          it will not be escaped before including it in the template.

       *          Alternatively, you could make the value type String, in which

       *          case the value would be escaped.

       * @return a {@link SafeHtml} instance

       */

     // @SafeHtmlTemplates.Template("<a href=\"{0}\">Download</div>")

     // SafeHtml cell(SafeStyles value);

     

      @Template("<a href=\"{0}\">{1}</a>")

      SafeHtml messageWithLink(String url, String linkText);

 

    }

 

    /**

     * Create a singleton instance of the templates used to render the cell.

     */

    private static Templates templates = GWT.create(Templates.class);

 

      @Override

      public void render(com.google.gwt.cell.client.Cell.Context context,

                  String value, SafeHtmlBuilder sb) {

              /*

             * Always do a null check on the value. Cell widgets can pass null to

             * cells if the underlying data contains a null, or if the data arrives

             * out of order.

             */

            if (value == null) {

              return;

            }

 

            // If the value comes from the user, we escape it to avoid XSS attacks.

          //  SafeHtml safeValue = SafeHtmlUtils.fromString(value);

 

            // Use the template to create the Cell's html.

            //SafeStyles safeValue = SafeStylesUtils.fromTrustedString(value);

            SafeHtml rendered = templates.messageWithLink(value,"Download");

            sb.append(rendered);

           

      }

 

     

 

}